package com.ecmcloud.common.dto;

import lombok.Data;

/**
 * 结果类
 * 统一返回值
 *
 * @param <T> 数据对象
 */
@Data
public class Result<T> {
    /**
     * 是否请求成功
     */
    private boolean ok;
    /**
     * 结果码
     */
    private Integer code;
    /**
     * 提示消息
     */
    private String msg = "业务处理成功";
    /**
     * 数据
     */
    private T data;

    public static <T> Result<T> success() {
        Result<T> r = new Result<T>();
        r.setOk(true);
        return r;
    }

    public static <T> Result<T> success(T data) {
        Result<T> r = new Result<T>();
        r.setOk(true);
        r.setData(data);
        return r;
    }

    public static <T> Result<T> fail(String msg) {
        Result<T> r = new Result<T>();
        r.setOk(false);
        r.setMsg(msg);
        return r;
    }

    public static <T> Result<T> success(T data,String msg) {
        Result<T> r = new Result<T>();
        r.setOk(true);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }
}
